<script >
function delete_purchase(p_detail_id)
{
	if(!window.confirm("请查看该订单是否已经进入付款流程？\n如果订单已经请款或付款，但是没取消或退款，请不要取消订单！"))
	{
		return ;
	}
	$.post(
				"<?php echo URL::site(); ?>purchase/deletepurchase",
				{p_detail_id:p_detail_id},
				function(re){

						if(re=='"cancel success"')
						{
							$("#re_"+p_detail_id).html("取消");
                            $("#uncancle").css('display',"block");
                            $("#cancle").css('display',"none");
							alert("取消成功");
							//var url = "searchpurchase?date_from=&date_to=&purchase_id=&purchaseorder_id=&supplier_id=&sku=&status=10";
							//window.location.href = "<?php echo url::base(true)?>purchases/select/"+url;
							
						}
						else if(re=='"flag"')
						{ 					
							alert("完结成功");
							$("#re_"+p_detail_id).html("手动完结");
						}else{
							alert("状态不适合完结、取消或未处理的存在不良品库存");
						}
		});
}
    function uncancle(p_detail_id)
    {
        if(!window.confirm("确定重新启用该sku吗？"))
        {
            return ;
        }
        $.post(
            "<?php echo URL::site(); ?>purchase/uncancle",
            {p_detail_id:p_detail_id},
            function(ok){
                if(ok==1)
                {
                    $("#cancle").css('display','block');
                    $("#uncancle").css('display','none');
                    $("#re_"+p_detail_id).html("已打印");
                }else{
                    alert("已超过采购下单时间5天，不允许启用");
                }
            });
    }
</script>
	<table class="table table-bordered" id="box1">
	 <tr class="headings">                             
                                    <th >
                                        SKU
                                    </th>
                                    <th >
                                        中文名称
                                    </th>
				    												<th >
                                        产品单价
                                    </th>
																		<th >
                                       	采购数量
                                    </th>
                                    <th >
                                        储位
                                    </th>
				    												<th >
                                        计税
                                    </th>
																		<th >
                                        明细添加时间
                                    </th>
				    												<th>
                                        收货量
                                    </th>
																		<th >
                                        质检量
                                    </th>
				    												<th>
                                        入库量
                                    </th>
																		<th >
                                        不合格量
                                    </th>
																		<th>
                                        状态
                                    </th>		
																		<th>
																			  操作  
																		</th>
                                </tr>
<?php if(isset($product_info)&&!empty($product_info)) {?>
						<?php foreach ($product_info as $p_in){?>
																<tr>
                                    <td >
                                        <?php echo $p_in['sku']?>
                                    </td>
                                    <td >
                                        <?php echo $p_in['sku_name']?>
                                    </td>
				    												<td >
                                        <?php echo $p_in['single_price']?>
                                    </td>
																		<td >
                                       	<?php echo $p_in['quantity']?>
                                    </td>
                                    <td >
                                        <?php echo $p_in['products_newplace']?>
                                    </td>
				    												<td >
                                        <?php if($p_in['tax_way']==0)echo "不计税";else if($p_in['tax_way']==-1) echo "价内税"; else if($p_in['tax_way']==1) echo "价外税";?>
                                    </td>
																		<td >
                                        <?php echo $p_in['details_date']?>
                                    </td>
				    												<td >
                                        <?php echo $p_in['arrival_quantity']?>
                                    </td>
																		<td >
                                        <?php echo $p_in['check_quantity']?>
                                    </td>		    		
				    												<td >
                                        <?php echo $p_in['ware_quantity']?>
                                    </td>
																		<td >
                                        <?php echo $p_in['qt']?>
                                    </td>
																		<td id="re_<?php echo $p_in['id'];?>">
                                        <?php echo $p_in['status']?>
                                    </td>			 						
                                    <td >
                                            <button id="cancle" onclick="delete_purchase(<?php echo $p_in['id']?>)" style="display: <?php if($p_in['status']=='取消'){echo 'none';}?>" class="btn btn btn-danger">取消</button>
                                            <button id="uncancle" onclick="uncancle(<?php echo $p_in['id']?>)" style="display: <?php if($p_in['status']!='取消'){echo 'none';}?>" class="btn btn btn-success">启用</button>
                                    </td>
																</tr>
<?php }}?>
	</table>


